<%--
  Created by IntelliJ IDEA.
  User: yoka24443
  Date: 2018-5-16
  Time: 19:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" contentType="text/html;charset=UTF-8" language="java" %>
<%
    Connection conn = null;
    Statement statement = null;
    String studentNO = request.getParameter("studentNO");
    StringBuilder output = new StringBuilder();

    try {
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.驱动管理器获取数据库链接
        conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school?user=root&password=&useUnicode=true&characterEncoding=utf8");
        //3.获取statement，执行sql
        statement = conn.createStatement();

        StringBuilder sql = new StringBuilder();
        if(studentNO != null && studentNO.trim().length() > 0) {
            sql.append(String.format("delete from student where studentNO = '%s'", studentNO));
            if (sql.length() > 0) {
                //4.执行sql返回结果集并解析
                statement.executeUpdate(sql.toString());
            }
        } else {
            output.append("studentNO is null");
        }

    } catch (ClassNotFoundException e) {
        out.println("连接数据库失败！<br/>" + e.getMessage());
    } catch (SQLException e) {
        out.println("SQL执行出错！<br/>" + e.getMessage());
    } catch (Exception e) {
        out.println(e.getMessage());
    } finally {
        try {
            if (statement != null) {
                statement.close();
            }
            if(conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            out.println(e.getMessage());
        }
    }
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <a href="StudentList.jsp">返回</a>
    <p>
        <h3>学生&nbsp;<font color="blue"><%=studentNO%></font>&nbsp;的信息删除成功</h3>
    </p>
</body>
</html>
